package project.dbaccesslayer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Table_SO_Users_Raw_html {

	public static String get_page(Connection conn, long id) throws SQLException {
		PreparedStatement s = conn
				.prepareStatement("SELECT html FROM SO_Users_Raw_html WHERE User_id = ? ");
		s.setLong(1, id);
		ResultSet r = s.executeQuery();
		r.next();
		String p = r.getString("html");
		return p;
	}

	public static void saveUserRawHtml(Connection conn, long id, String html)
			throws SQLException {
		PreparedStatement s = conn
				.prepareStatement("INSERT INTO SO_Users_Raw_html"
						+ "(User_id, html) VALUES(?,?)");
		s.setLong(1, id);
		s.setString(2, html);

		s.executeUpdate();
	}

	public static List<Long> getUsersToDownload(Connection conn)
			throws SQLException {
		PreparedStatement s = conn.prepareStatement("CALL GetUsersToDownload(); ");
		ResultSet r = s.executeQuery();
		List<Long> ids = new ArrayList<Long>();
		while (r.next()) {
			ids.add(r.getLong("User_Id"));
		}
		return ids;
	}
	
}
